package archer.back.controllers

import play.api.mvc.ControllerComponents
import utils.{ArcherHelper, CommonDB}
import io.circe.syntax._

class PlanController(
    controllerComponents: ControllerComponents,
    planService: PlanService,
) extends BackController(controllerComponents)
    with ArcherHelper {

  implicit val ec = defaultExecutionContext

  import models.CrawlTables._

  def list = Action.async { implicit request =>
    R.toJsonResult(planService.list)
  }

  def retrieve(id: Int) = Action.async { implicit request =>
    R.toJsonResult(planService.retrieve(id))
  }

  def update = Action.async(circe.json[CrawlPlanRow]) { implicit request =>
    R.toJsonResult(planService.update(request.body))
  }

  def create = Action.async(circe.json[CrawlPlanRow]) { implicit request =>
    R.toJsonResult(planService.create(request.body))
  }

  def delete(id: Int) = Action.async { implicit request =>
    R.toJsonResult(planService.delete(id))
  }
  /*def start(id: Int) = Action.async { implicit request =>
    R.toJsonResult(planService.start(id))
  }*/
}
